home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows 95 with MFC / Programming Windows 95 with MFC (Microsoft Programming Series)(097-0001465)(1996).iso / CODE / Chap09 / Paint5 / CLine.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-05  |  907 b   |  40 lines

  1. //***********************************************************************
  2. //
  3. //  CLine.cpp
  4. //
  5. //***********************************************************************
  6.  
  7. #include <afxwin.h>
  8. #include "CLine.h"
  9.  
  10. IMPLEMENT_SERIAL (CLine, CObject, 1)
  11.  
  12. CLine::CLine (CPoint ptFrom, CPoint ptTo, UINT nWidth, COLORREF crColor)
  13. {
  14.     m_ptFrom = ptFrom;
  15.     m_ptTo = ptTo;
  16.     m_nWidth = nWidth;
  17.     m_crColor = crColor;
  18. }
  19.  
  20. void CLine::Serialize (CArchive& ar)
  21. {
  22.     CObject::Serialize (ar);
  23.  
  24.     if (ar.IsStoring ())
  25.         ar << m_ptFrom << m_ptTo << m_nWidth << (DWORD) m_crColor;
  26.     else
  27.         ar >> m_ptFrom >> m_ptTo >> m_nWidth >> (DWORD) m_crColor;
  28. }
  29.  
  30. void CLine::Draw (CDC* pDC)
  31. {
  32.     CPen pen (PS_SOLID, m_nWidth, m_crColor);
  33.  
  34.     CPen* pOldPen = pDC->SelectObject (&pen);
  35.     pDC->MoveTo (m_ptFrom);
  36.     pDC->LineTo (m_ptTo);
  37.  
  38.     pDC->SelectObject (pOldPen);
  39. }
  40.